﻿using System;
using System.IO;
using System.Runtime.Serialization;
using UnityEngine;

// Token: 0x020002D3 RID: 723
[Serializable]
public abstract class CharFileInfoClothes
{
	// Token: 0x0600117E RID: 4478 RVA: 0x0008E998 File Offset: 0x0008CB98
	public CharFileInfoClothes(string fileMarkName, string fileDirectory, int cknum)
	{
		this.ClothesFileMark = fileMarkName;
		this.ClothesFileDirectory = fileDirectory;
		this.clothesKindNum = cknum;
		this.clothesId = new int[this.clothesKindNum];
		this.clothesColor = new global::HSColorSet[this.clothesKindNum];
		this.clothesColor2 = new global::HSColorSet[this.clothesKindNum];
		this.accessory = new global::CharFileInfoClothes.Accessory[10];
		for (int i = 0; i < this.accessory.Length; i++)
		{
			this.accessory[i] = new global::CharFileInfoClothes.Accessory();
		}
		this.comment = "コーディネート名";
	}

	// Token: 0x17000273 RID: 627
	// (get) Token: 0x0600117F RID: 4479 RVA: 0x0008EA60 File Offset: 0x0008CC60
	// (set) Token: 0x06001180 RID: 4480 RVA: 0x0008EA68 File Offset: 0x0008CC68
	public global::CharFileInfoClothes.Accessory[] accessory
	{
		get
		{
			return this._accessory;
		}
		set
		{
			this._accessory = value;
		}
	}

	// Token: 0x06001181 RID: 4481 RVA: 0x0008EA74 File Offset: 0x0008CC74
	public void MemberInitialize()
	{
	}

	// Token: 0x06001182 RID: 4482
	public abstract bool Copy(global::CharFileInfoClothes srcData);

	// Token: 0x06001183 RID: 4483 RVA: 0x0008EA78 File Offset: 0x0008CC78
	public string ConvertClothesFilePath(string path, bool newFile = false)
	{
		string text = string.Empty;
		string text2 = string.Empty;
		if (path != string.Empty)
		{
			text = Path.GetDirectoryName(path);
			text2 = Path.GetFileName(path);
		}
		if (text == string.Empty)
		{
			text = global::UserData.Path + this.ClothesFileDirectory;
		}
		else
		{
			text += "/";
		}
		if (text2 == string.Empty)
		{
			if (newFile || this.clothesFileName == string.Empty)
			{
				string empty = string.Empty;
				if (this.clothesTypeSex == 0)
				{
					text2 = "coordM" + empty + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
				}
				else
				{
					text2 = "coordF" + empty + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
				}
			}
			else
			{
				text2 = this.clothesFileName;
			}
		}
		this.clothesFileName = Path.GetFileNameWithoutExtension(text2) + ".png";
		return text + this.clothesFileName;
	}

	// Token: 0x06001184 RID: 4484 RVA: 0x0008EB98 File Offset: 0x0008CD98
	public bool Save(string path)
	{
		string path2 = this.ConvertClothesFilePath(path, false);
		string directoryName = Path.GetDirectoryName(path2);
		if (!Directory.Exists(directoryName))
		{
			Directory.CreateDirectory(directoryName);
		}
		bool result;
		using (FileStream fileStream = new FileStream(path2, FileMode.Create, FileAccess.Write))
		{
			using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
			{
				result = this.Save(binaryWriter);
			}
		}
		return result;
	}

	// Token: 0x06001185 RID: 4485 RVA: 0x0008EC28 File Offset: 0x0008CE28
	public bool Save(BinaryWriter bw)
	{
		if (this.clothesPNG != null)
		{
			bw.Write(this.clothesPNG);
		}
		long position = bw.BaseStream.Position;
		this.SaveWithoutPNG(bw);
		bw.Write(position);
		return true;
	}

	// Token: 0x06001186 RID: 4486 RVA: 0x0008EC68 File Offset: 0x0008CE68
	public bool SaveWithoutPNG(BinaryWriter bw)
	{
		bw.Write(this.ClothesFileMark);
		bw.Write(3);
		bw.Write(1);
		bw.Write(this.clothesKindNum);
		for (int i = 0; i < this.clothesKindNum; i++)
		{
			bw.Write(this.clothesId[i]);
			this.clothesColor[i].Save(bw);
			this.clothesColor2[i].Save(bw);
		}
		bw.Write(10);
		for (int j = 0; j < 10; j++)
		{
			this.accessory[j].Save(bw);
		}
		bw.Write(this.comment);
		bw.Write(this.clothesTypeSex);
		return this.SaveSub(bw);
	}

	// Token: 0x06001187 RID: 4487 RVA: 0x0008ED24 File Offset: 0x0008CF24
	public bool Load(string path, bool noSetPng = false)
	{
		string path2 = this.ConvertClothesFilePath(path, false);
		if (!File.Exists(path2))
		{
			return false;
		}
		this.clothesFileName = Path.GetFileName(path2);
		bool result;
		using (FileStream fileStream = new FileStream(path2, FileMode.Open, FileAccess.Read))
		{
			using (BinaryReader binaryReader = new BinaryReader(fileStream))
			{
				result = this.Load(binaryReader, noSetPng);
			}
		}
		return result;
	}

	// Token: 0x06001188 RID: 4488 RVA: 0x0008EDB4 File Offset: 0x0008CFB4
	public bool Load(string assetBundleName, string assetName, bool noSetPNG = false)
	{
		TextAsset textAsset = global::CommonLib.LoadAsset<TextAsset>(assetBundleName, assetName, false, string.Empty);
		if (null == textAsset)
		{
			return false;
		}
		global::AssetBundleManager.UnloadAssetBundle(assetBundleName, true, null);
		return this.Load(textAsset, noSetPNG);
	}

	// Token: 0x06001189 RID: 4489 RVA: 0x0008EDF0 File Offset: 0x0008CFF0
	public bool Load(TextAsset ta, bool noSetPNG = false)
	{
		if (null == ta)
		{
			return false;
		}
		bool result;
		using (MemoryStream memoryStream = new MemoryStream())
		{
			memoryStream.Write(ta.bytes, 0, ta.bytes.Length);
			memoryStream.Seek(0L, SeekOrigin.Begin);
			result = this.Load(memoryStream, noSetPNG);
		}
		return result;
	}

	// Token: 0x0600118A RID: 4490 RVA: 0x0008EE64 File Offset: 0x0008D064
	public bool Load(Stream st, bool noSetPNG = false)
	{
		bool result;
		using (BinaryReader binaryReader = new BinaryReader(st))
		{
			result = this.Load(binaryReader, noSetPNG);
		}
		return result;
	}

	// Token: 0x0600118B RID: 4491 RVA: 0x0008EEAC File Offset: 0x0008D0AC
	public bool Load(BinaryReader br, bool noSetPng = false)
	{
		long num = 0L;
		if (noSetPng)
		{
			global::PngAssist.CheckPngData(br, ref num, true);
		}
		else
		{
			this.clothesPNG = global::PngAssist.LoadPngData(br);
		}
		if (!this.LoadWithoutPNG(br))
		{
			return false;
		}
		num = br.ReadInt64();
		return true;
	}

	// Token: 0x0600118C RID: 4492 RVA: 0x0008EEF4 File Offset: 0x0008D0F4
	public bool LoadWithoutPNG(BinaryReader br)
	{
		if (br.BaseStream.Length - br.BaseStream.Position == 0L)
		{
			global::Debug.LogWarning("ただのPNGファイルの可能性があります。");
			return false;
		}
		try
		{
			string a = br.ReadString();
			if (a != this.ClothesFileMark)
			{
				return false;
			}
			this.clothesLoadFileVersion = br.ReadInt32();
			if (this.clothesLoadFileVersion > 3)
			{
				return false;
			}
			int num = br.ReadInt32();
			int num2 = br.ReadInt32();
			for (int i = 0; i < num2; i++)
			{
				this.clothesId[i] = br.ReadInt32();
				this.clothesColor[i].Load(br, num);
				if (3 <= this.clothesLoadFileVersion)
				{
					this.clothesColor2[i].Load(br, num);
				}
			}
			num2 = br.ReadInt32();
			for (int j = 0; j < num2; j++)
			{
				this.accessory[j].Load(br, this.clothesLoadFileVersion, num);
			}
			if (2 <= this.clothesLoadFileVersion)
			{
				this.comment = br.ReadString();
				this.clothesTypeSex = br.ReadByte();
			}
			return this.LoadSub(br, this.clothesLoadFileVersion, num);
		}
		catch (EndOfStreamException ex)
		{
			global::Debug.LogError("データが破損している可能性があります：" + ex.GetType().Name);
		}
		return false;
	}

	// Token: 0x0600118D RID: 4493
	public abstract bool SaveSub(BinaryWriter bw);

	// Token: 0x0600118E RID: 4494
	public abstract bool LoadSub(BinaryReader br, int clothesVer, int colorVer);

	// Token: 0x040017A5 RID: 6053
	public const int ClothesFileVersion = 3;

	// Token: 0x040017A6 RID: 6054
	public readonly string ClothesFileMark = string.Empty;

	// Token: 0x040017A7 RID: 6055
	public readonly string ClothesFileDirectory = string.Empty;

	// Token: 0x040017A8 RID: 6056
	public byte[] clothesPNG;

	// Token: 0x040017A9 RID: 6057
	public string clothesFileName = string.Empty;

	// Token: 0x040017AA RID: 6058
	public int clothesLoadFileVersion;

	// Token: 0x040017AB RID: 6059
	public readonly int clothesKindNum;

	// Token: 0x040017AC RID: 6060
	public int[] clothesId;

	// Token: 0x040017AD RID: 6061
	public global::HSColorSet[] clothesColor;

	// Token: 0x040017AE RID: 6062
	public global::HSColorSet[] clothesColor2;

	// Token: 0x040017AF RID: 6063
	public string comment = string.Empty;

	// Token: 0x040017B0 RID: 6064
	public byte clothesTypeSex;

	// Token: 0x040017B1 RID: 6065
	public global::CharFileInfoClothes.Accessory[] _accessory;

	// Token: 0x020002D4 RID: 724
	[Serializable]
	public class Accessory : ISerializable
	{
		// Token: 0x0600118F RID: 4495 RVA: 0x0008F074 File Offset: 0x0008D274
		public Accessory()
		{
		}

		// Token: 0x06001190 RID: 4496 RVA: 0x0008F0D8 File Offset: 0x0008D2D8
		public Accessory(SerializationInfo info, StreamingContext context)
		{
			this.type = info.GetInt32("type");
			this.id = info.GetInt32("id");
			this.parentKey = info.GetString("parentKey");
			this.addPos.x = info.GetSingle("addPosX");
			this.addPos.y = info.GetSingle("addPosY");
			this.addPos.z = info.GetSingle("addPosZ");
			this.addRot.x = info.GetSingle("addRotX");
			this.addRot.y = info.GetSingle("addRotY");
			this.addRot.z = info.GetSingle("addRotZ");
			this.addScl.x = info.GetSingle("addSclX");
			this.addScl.y = info.GetSingle("addSclY");
			this.addScl.z = info.GetSingle("addSclZ");
			this.color.hsvDiffuse.H = info.GetSingle("diffuseH");
			this.color.hsvDiffuse.S = info.GetSingle("diffuseS");
			this.color.hsvDiffuse.V = info.GetSingle("diffuseV");
			this.color.alpha = info.GetSingle("alpha");
			this.color.hsvSpecular.H = info.GetSingle("specularH");
			this.color.hsvSpecular.S = info.GetSingle("specularS");
			this.color.hsvSpecular.V = info.GetSingle("specularV");
			this.color.specularIntensity = info.GetSingle("specularIntensity");
			this.color.specularSharpness = info.GetSingle("specularSharpness");
			this.color2.hsvDiffuse.H = info.GetSingle("diffuseH2");
			this.color2.hsvDiffuse.S = info.GetSingle("diffuseS2");
			this.color2.hsvDiffuse.V = info.GetSingle("diffuseV2");
			this.color2.alpha = info.GetSingle("alpha2");
			this.color2.hsvSpecular.H = info.GetSingle("specularH2");
			this.color2.hsvSpecular.S = info.GetSingle("specularS2");
			this.color2.hsvSpecular.V = info.GetSingle("specularV2");
			this.color2.specularIntensity = info.GetSingle("specularIntensity2");
			this.color2.specularSharpness = info.GetSingle("specularSharpness2");
		}

		// Token: 0x06001191 RID: 4497 RVA: 0x0008F3FC File Offset: 0x0008D5FC
		public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("type", this.type);
			info.AddValue("id", this.id);
			info.AddValue("parentKey", this.parentKey);
			info.AddValue("addPosX", this.addPos.x);
			info.AddValue("addPosY", this.addPos.y);
			info.AddValue("addPosZ", this.addPos.z);
			info.AddValue("addRotX", this.addRot.x);
			info.AddValue("addRotY", this.addRot.y);
			info.AddValue("addRotZ", this.addRot.z);
			info.AddValue("addSclX", this.addScl.x);
			info.AddValue("addSclY", this.addScl.y);
			info.AddValue("addSclZ", this.addScl.z);
			info.AddValue("diffuseH", this.color.hsvDiffuse.H);
			info.AddValue("diffuseS", this.color.hsvDiffuse.S);
			info.AddValue("diffuseV", this.color.hsvDiffuse.V);
			info.AddValue("alpha", this.color.alpha);
			info.AddValue("specularH", this.color.hsvSpecular.H);
			info.AddValue("specularS", this.color.hsvSpecular.S);
			info.AddValue("specularV", this.color.hsvSpecular.V);
			info.AddValue("specularIntensity", this.color.specularIntensity);
			info.AddValue("specularSharpness", this.color.specularSharpness);
			info.AddValue("diffuseH2", this.color2.hsvDiffuse.H);
			info.AddValue("diffuseS2", this.color2.hsvDiffuse.S);
			info.AddValue("diffuseV2", this.color2.hsvDiffuse.V);
			info.AddValue("alpha2", this.color2.alpha);
			info.AddValue("specularH2", this.color2.hsvSpecular.H);
			info.AddValue("specularS2", this.color2.hsvSpecular.S);
			info.AddValue("specularV2", this.color2.hsvSpecular.V);
			info.AddValue("specularIntensity2", this.color2.specularIntensity);
			info.AddValue("specularSharpness2", this.color2.specularSharpness);
		}

		// Token: 0x06001192 RID: 4498 RVA: 0x0008F6CC File Offset: 0x0008D8CC
		public void MemberInitialize()
		{
			this.type = -1;
			this.id = -1;
			this.parentKey = string.Empty;
			this.addPos = Vector3.zero;
			this.addRot = Vector3.zero;
			this.addScl = Vector3.one;
			this.color = new global::HSColorSet();
			this.color2 = new global::HSColorSet();
		}

		// Token: 0x06001193 RID: 4499 RVA: 0x0008F72C File Offset: 0x0008D92C
		public void Copy(global::CharFileInfoClothes.Accessory src)
		{
			this.type = src.type;
			this.id = src.id;
			this.parentKey = src.parentKey;
			this.addPos = src.addPos;
			this.addRot = src.addRot;
			this.addScl = src.addScl;
			this.color.Copy(src.color);
			this.color2.Copy(src.color2);
		}

		// Token: 0x06001194 RID: 4500 RVA: 0x0008F7A4 File Offset: 0x0008D9A4
		public void Save(BinaryWriter writer)
		{
			writer.Write(this.type);
			writer.Write(this.id);
			writer.Write(this.parentKey);
			writer.Write(this.addPos.x);
			writer.Write(this.addPos.y);
			writer.Write(this.addPos.z);
			writer.Write(this.addRot.x);
			writer.Write(this.addRot.y);
			writer.Write(this.addRot.z);
			writer.Write(this.addScl.x);
			writer.Write(this.addScl.y);
			writer.Write(this.addScl.z);
			this.color.Save(writer);
			this.color2.Save(writer);
		}

		// Token: 0x06001195 RID: 4501 RVA: 0x0008F888 File Offset: 0x0008DA88
		public void Load(BinaryReader reader, int verClothes, int verColor)
		{
			this.type = reader.ReadInt32();
			this.id = reader.ReadInt32();
			this.parentKey = reader.ReadString();
			this.addPos.x = reader.ReadSingle();
			this.addPos.y = reader.ReadSingle();
			this.addPos.z = reader.ReadSingle();
			this.addRot.x = reader.ReadSingle();
			this.addRot.y = reader.ReadSingle();
			this.addRot.z = reader.ReadSingle();
			this.addScl.x = reader.ReadSingle();
			this.addScl.y = reader.ReadSingle();
			this.addScl.z = reader.ReadSingle();
			this.color.Load(reader, verColor);
			if (3 <= verClothes)
			{
				this.color2.Load(reader, verColor);
			}
		}

		// Token: 0x040017B2 RID: 6066
		public int type = -1;

		// Token: 0x040017B3 RID: 6067
		public int id = -1;

		// Token: 0x040017B4 RID: 6068
		public string parentKey = string.Empty;

		// Token: 0x040017B5 RID: 6069
		public Vector3 addPos = Vector3.zero;

		// Token: 0x040017B6 RID: 6070
		public Vector3 addRot = Vector3.zero;

		// Token: 0x040017B7 RID: 6071
		public Vector3 addScl = Vector3.one;

		// Token: 0x040017B8 RID: 6072
		public global::HSColorSet color = new global::HSColorSet();

		// Token: 0x040017B9 RID: 6073
		public global::HSColorSet color2 = new global::HSColorSet();
	}
}
